package com.singzi.javaSenior.threads.threadLocal.demo;

public class DemoLocal {
    private static ThreadLocal<String>threadLocal = new ThreadLocal<>();

    private String info;

    public String getInfo() {
        return threadLocal.get();
    }
    private void setInfo(String info) {
        threadLocal.set(info);
    }

    public static void main(String[] args) {
        DemoLocal demo = new DemoLocal();
        for (int i = 0; i < 5; i++) {
            Thread thread = new Thread(new Runnable() {
                @Override
                public void run() {
                    demo.setInfo(Thread.currentThread().getName() + "的数据");
                    System.out.println("-----------------------");
                    System.out.println(Thread.currentThread().getName() + "--->" + demo.getInfo());
                }

            });
            thread.setName("线程" + i);
            thread.start();

        }
    }
}
